package com.tong.ft_main;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;

import com.tong.ft_main.databinding.ActivityMainBinding;
import com.tong.ft_main.param.frag.AppFragments;
import com.tong.lib_base.base.BaseActivity;
import com.tong.lib_base.ft_home.service.impl.HomeImpl;
import com.tong.lib_base.ft_my.service.impl.MyImpl;

/**
 * author:liuzhitong
 * date:2022/3/2
 * description:
 */
public class MainActivity extends BaseActivity {

    private ActivityMainBinding mBinding;
    public static void start(Context context){
        Intent intent = new Intent(context,MainActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this,R.layout.activity_main);
        initBottomTabBar();
    }

    private void initBottomTabBar() {
        mBinding.bottomTabBar.init(getSupportFragmentManager(), 750, 1334)
                .setImgSize(50,50)
                .setFontSize(10)
                .setTabPadding(4,6,10)
                .setChangeColor(getResources().getColor(R.color.text_select),getResources().getColor(R.color.text_unselect))
                .addTabItem("首页", R.mipmap.icon_home_true, R.mipmap.icon_home_false, getFragment(AppFragments.FRAGMENT_HOME))
                .addTabItem("我的", R.mipmap.icon_my_true, R.mipmap.icon_my_false, getFragment(AppFragments.FRAGMENT_MY))
                .setOnTabChangeListener((position, name, view) -> {
                }).setSpot(1, false);
        mBinding.bottomTabBar.setTabBarBackgroundColor(getResources().getColor(R.color.color_base_bg));
        mBinding.bottomTabBar.setDividerColor(getResources().getColor(R.color.black));
    }

    public Class<?> getFragment(Enum e){
        if(AppFragments.FRAGMENT_HOME == e){
            return HomeImpl.getInstance().getFragment(this).getClass();
        }else if(AppFragments.FRAGMENT_MY == e){
            return MyImpl.getInstance().getMyFragInstance(this).getClass();
        }
        //后期返回一个默认fragment
       return HomeImpl.getInstance().getFragment(this).getClass();
    }
}
